// #ifndef VUE3
import Vue from 'vue'
import App from './App'
import {
	$http
} from '@escook/request-miniprogram'
import store from './store/index.js'
import {
	mixin
} from '@/mixins'

Vue.config.productionTip = false
uni.$http = $http
// 配置请求根路径
$http.baseUrl = 'https://admin.dingshengtaiqiu.com'
// $http.baseUrl = 'http://192.168.2.211:8087'
// 请求开始之前做一些事情
$http.beforeRequest = function(options) {
	uni.showLoading({ 
		title: '数据加载中...',
	})

	if (store.state.token) {
		options.header = {
			"x-token": store.state.token,
		}
	}
}
// 请求完成之后做一些事情
$http.afterRequest = function(res) {
	uni.hideLoading()
	// if (res.data.code == 1) {
	// 	uni.$showMsg('请重新登录')
	// 	getApp().globalData.fromPath = getCurrentPages()[getCurrentPages().length - 1].$page.fullPath
	// 	uni.redirectTo({
	// 		url: "/pages/other/login"
	// 	})
	// }
	// if (res.statusCode == 200 && res.data != undefined && res.data.code == 1) {
	// 	uni.$showMsg('请重新登录')
	// 	store.commit('Logout');
	// 	uni.redirectTo({
	// 		url: "/pages/courseList/courseList"
	// 	})
	// }
}

// 封装的展示消息提示的方法
uni.$showMsg = function(title = '数据加载失败！', duration = 1500, icon = 'none') {
	uni.showToast({
		title,
		duration,
		icon,
	})
}
App.mpType = 'app'

Vue.mixin(mixin);
const app = new Vue({
	store,
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
import App from './App.vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif
